﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace GeuzenAdministratie
{
    public partial class Form1 : Form
    {
        DBConnect db = new DBConnect();

        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            //this.TopMost = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            pictureBox1.Left = (this.ClientSize.Width - pictureBox1.Width) / 2;
            label1.Left = (this.ClientSize.Width - label1.Width) / 2;
            textBox1.Left = (this.ClientSize.Width - textBox1.Width) / 2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MemberAdmin MA = new MemberAdmin();
            MA.Show();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            DBConnect db = new DBConnect();
            if (e.KeyChar == (char)13) // Then Enter key was pressed, possibly scanner uses different keycode!
            {
                if (textBox1.Text == "99999")//als admincode wordt gepresenteerd, adminpaneel openen
                {
                    MemberAdmin MA = new MemberAdmin();
                    MA.Show();
                }
                else
                {
                    try
                    {
                        DataRow row = db.getMemberByKNSA(textBox1.Text).Rows[0];
                        string initial = row["initial"].ToString();
                        string tussenvoegsel = row["tussenvoegsel"].ToString();
                        string lastName = row["lastName"].ToString();
                        string knsa = row["KNSA"].ToString();
                        if (db.getAanwezigVandaag(knsa)==true) //controleren of persoon niet toevallig al aanwezig is
                        {
                            Error reject = new Error(initial, tussenvoegsel, lastName, knsa);
                            
                        }
                        else
                        {
                            db.setAanwezig(knsa);
                            WelcomeUser welcome = new WelcomeUser(initial, tussenvoegsel, lastName, knsa);
                            welcome.Show();
                        }

                    }
                    catch (IndexOutOfRangeException ex)
                    {
                    }
                }
                textBox1.Text = "";//box leegmaken voor volgende gebruiker

            }

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

    }
}
